<template>
  <view class="container">
    <view class="form">
      <text class="title">登录</text>
      <input class="input" placeholder="请输入用户名" v-model="username" />
      <input class="input" placeholder="请输入密码" type="password" v-model="password" />
      <button class="login-btn" @click="handleLogin">登录</button>
      <navigator url="/pages/register/register" class="register-link">没有账号？去注册</navigator>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      username: '',
      password: '',
      registeredUsers: [
        { username: 'kjw', password: '123456' },
        { username: 'user2', password: 'abc123' }
      ]
    };
  },
  methods: {
    handleLogin() {
      if (!this.username) {
        uni.showToast({
          title: '请输入用户名',
          icon: 'none',
        });
        return;
      }
      if (!this.password) {
        uni.showToast({
          title: '请输入密码',
          icon: 'none',
        });
        return;
      }
      const user = this.registeredUsers.find(
        (u) => u.username === this.username && u.password === this.password
      );
      if (user) {
        uni.showToast({
          title: '登录成功',
          icon: 'success',
        });
        uni.switchTab({
          url: '/pages/aaa/zj/zj',
        });
      } else {
        uni.showToast({
          title: '用户名或密码错误',
          icon: 'none',
        });
      }
    },
  },
};
</script>

<style>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
}
.form {
  width: 80%;
  background-color: #fff;
  padding: 30rpx;
  border-radius: 10rpx;
  box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.title {
  font-size: 40rpx;
  font-weight: bold;
  margin-bottom: 30rpx;
}
.input {
  width: 100%;
  height: 80rpx;
  border: 1rpx solid #ddd;
  border-radius: 6rpx;
  padding: 0 20rpx;
  margin-bottom: 20rpx;
  box-sizing: border-box;
}
.login-btn {
  width: 100%;
  height: 80rpx;
  background-color: #1677ff;
  color: #fff;
  border-radius: 6rpx;
  margin-top: 20rpx;
}
.register-link {
  margin-top: 20rpx;
  font-size: 28rpx;
  color: #1677ff;
}
</style>